package invoker;

import command.Command;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 游戏角色，命令接收者，负责执行命令
 */
public class GameCharacter {

    /**
     * 预输入指令
     */
    private final Queue<Command> preInputCommand;

    public GameCharacter() {
        this.preInputCommand = new LinkedList<>();
    }

    public void inputCommand(Command operate) {
        this.preInputCommand.add(operate);
    }

    public void executeCommand() {
        if (this.preInputCommand.isEmpty()) {
            System.out.println("没有输入任何指令");
            return;
        }
        Command command = this.preInputCommand.poll();
        command.execute();
    }

    public void executeAllCommand() {
        if (this.preInputCommand.isEmpty()) {
            System.out.println("没有输入任何指令");
            return;
        }
        Queue<Command> commands = this.preInputCommand;
        while (!commands.isEmpty()) {
            commands.poll().execute();
        }
    }
}
